<?php
namespace app\controller\v1;

use think\facade\View;

use app\controller\v1\Base;
use app\model\Article;
use app\model\Industry;
use app\model\ProductsWire;
use app\model\ProductsSurface;
use app\model\ProductsWearPlate;

class Index extends Base
{
    public function index()
    {
        return View::fetch();
    }

    public function hello()
    {
        return '正在建设中.....';
    }

    public function about()
    {
        return View::fetch();
    }

    public function development()
    {
        return View::fetch();
    }

    public function honor()
    {
        return View::fetch();
    }

    public function factory()
    {
        return View::fetch();
    }

    public function contactus()
    {
        return View::fetch();
    }

    public function search($key = "")
    {
        $key = $this->request->has('key') ? (string)$this->request->param('key') : '';

        $news_list = $product_list = $industry_list = null;

        if ($key != '') {
            $news_list = Article::where('title|keywords', 'LIKE', '%' . $key . '%')->where('status', 1)->field('id,cid,title,titlepic,username,summary,hits,sort,pubtime')->select();

            $product_list_wire       = ProductsWire::where('title|productstype', 'LIKE', '%' . $key . '%')->field('id, productstype, application')->select();
            $product_list_surface    = ProductsSurface::where('productstype', 'LIKE', '%' . $key . '%')->field('id, productstype, application')->select();
            $product_list_wear_plate = ProductsWearPlate::where('products_number', 'LIKE', '%' . $key . '%')->field('id, products_number, instruction')->select();

            $product_list['product_list_wire']       = $product_list_wire;
            $product_list['product_list_surface']    = $product_list_surface;
            $product_list['product_list_wear_plate'] = $product_list_wear_plate;

            $industry_list = Industry::where('title|keywords', 'LIKE', '%' . $key . '%')->field('id,title,titlepic,summary,create_time')->select();
        }

        return View::fetch('', [
            'news_list'     => $news_list,
            'product_list'  => $product_list,
            'industry_list' => $industry_list
        ]);
    }

    
    public function test()
    {
        return "this is test";
    }
}
